package ar.com.laley.centro.servicios;

import static ar.com.laley.centro.common.Constantes.DISPOSITION;
import static ar.com.laley.centro.common.Constantes.ENCODING;
import static ar.com.laley.centro.common.Constantes.ENCODING_UTF8;
import static ar.com.laley.centro.common.Constantes.EXPIRE;

import java.util.HashMap;
import java.util.Map;

import ar.com.laley.centro.utils.AdministradorDeFechas;

enum Formato {
	pdf, xls, word
};

public abstract class ServicioDelivery {

	public static Map<String, String> getDeliveryHeaderParams(String formato) {

		Formato formatoDelivery = Formato.valueOf(formato);
		Map<String, String> params = new HashMap<String, String>();

		params.put(DISPOSITION, "attachment;filename=" + "consulta" + "-"
				+ AdministradorDeFechas.now()
				+ resolveExtension(formatoDelivery));
		params.put(ENCODING, ENCODING_UTF8);
		params.put(EXPIRE,
				"Cache-Control: must-revalidate, post-check=0, pre-check=0");

		return params;
	}

	private static String resolveExtension(Formato formato) {
		String ext = "";

		switch (formato) {

		case pdf:
			ext = ".pdf";
			break;
		case xls:
			ext = ".xls";
			break;
		case word:
			ext = ".doc";
			break;
		}
		return ext;
	}
}
